//
//  KSSwitchItem.swift
//  ANOA
//
//  Created by 邱仙凯 on 2022/4/25.
//  Copyright © 2025 aowang. All rights reserved.
//  开关

import UIKit

class KSSwitchItem: KSFormHItem {
    // MARK: - 懒加载 lazy
     lazy var switchX:UISwitch = {
        let v = UISwitch()
        return v
    }()
    override func disabledChange() {
        titleLabColorAdapt()
    
         self.switchX.isUserInteractionEnabled = !disabled
    }
    var switchValueChangeClo:((Bool)->())?
    convenience init(title:String,appearance: KSFormBaseAppear? = KSFormBaseAppear()) {
        self.init(title: title, appearance: appearance,type:.switchx)
        self.textView.isHidden = true
        self.assistBtn.isHidden = true
        self.addSubview(switchX)
        switchX.snp.makeConstraints { make in
             make.height.equalTo(27)
            make.right.equalTo(self).offset(-self.appearance.contentTrailing)
            make.centerY.equalTo(self)
        }
        switchX.addTarget(self, action: #selector(switchChange(sender:)), for: .valueChanged)
     }
    
    @objc private func switchChange(sender:UISwitch) {
        if let clo = switchValueChangeClo {
            clo(sender.isOn)
        }
    }
    //设置开关
    func setSwitchOn(_ onx:Bool) {
        self.switchX.isOn = onx
    }
}
 





